<extend name="public:template" />
<block name="title">角色授权</block>
<block name="style"></block>
<block name="content">

    <div class="wrap-page">
        <div id="pageBookList" class="page-content">
            <div id="boxBookList" class="box">
                <div class="box-content">
                    <form action="{:U('admin_role/auth')}" method="post">
                    <div class="wrap-table">
                        <div class="table-bar table-bar-head clearfix">
                            <div class="fl-l">
                                <div class="tools">
                                    <label class="select_all " ><input type="checkbox" name="checkall" class="J_checkall" >{:L('select_all')}/{:L('cancel')}</label>
                                </div>
                            </div>
                            <div class="fl-r">
                                <div class="tools">
                                    <span class="tool-item"><button onclick="javascript:window.location.replace(window.location.href);" class="button button-default" type="button">刷新列表</button></span>
                                </div>
                            </div>
                        </div>

                        <table class="table default-style" cellpadding="0" cellspacing="0" width="100%">
                            <thead>
                            <tr><th><div class="th th-inner al-l">{:L('authorize')} - {$role.name}</div></th></tr>
                            </thead>
                            <tbody>
                            {$list}
                            </tbody>
                        </table>
                            <input type="hidden" name="id" value="{$role.id}"></input>
                    </div>
                        <div class="page-buttons clearfix">
                            <div class="fl-l">
                                <button type="submit" class="button button-blue" id="save">保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</block>
<block name="script">
    <script src="__STATIC__/admin/js/treetable.js"></script>
    <script>
        $(document).ready(function(){

            $("#J_auth_tree").treeTable({indent:20});

            $('.J_checkitem').on('click',function(){
                var chk = $("input[type='checkbox']"),
                        count = chk.length;
                num = chk.index($(this));
                level_top = level_bottom =  chk.eq(num).attr('level');
                for(var i=num; i>=0; i--){
                    var le = chk.eq(i).attr('level');
                    if(eval(le) < eval(level_top)){
                        chk.eq(i).prop("checked", 'checked');
                        var level_top = level_top-1;
                    }
                }
                for(var j=num+1; j<count; j++){
                    var le = chk.eq(j).attr('level');
                    if(chk.eq(num).prop("checked")) {
                        if(eval(le) > eval(level_bottom)) chk.eq(j).prop("checked", 'checked');
                        else if(eval(le) == eval(level_bottom)) break;
                    }else{
                        if(eval(le) > eval(level_bottom)) chk.eq(j).prop("checked", false);
                        else if(eval(le) == eval(level_bottom)) break;
                    }
                }
            });
        });
    </script>
</block>